package com.example.service.impl;

import com.example.mapper.AttractionMapper;
import com.example.pojo.Attraction;
import com.example.pojo.AttractionResult;
import com.example.service.AttractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AttractionServiceImpl implements AttractionService {

    @Autowired
    private AttractionMapper attractionMapper;

    @Override
    public AttractionResult getTopAttractions() {
        // 1. 查询本周访客量前9的景点（按降序）
        List<Attraction> top9Attractions = attractionMapper.selectTop9ByVisitor();

        // 2. 拆分数据：第1条为leftSrc，剩余8条为rightSrc
        AttractionResult result = new AttractionResult();
        if (!top9Attractions.isEmpty()) {
            result.setLeftSrc(top9Attractions.get(0)); // 第1条（访客量最高）
            // 从第2条开始取，最多取8条（若不足9条则取剩余所有）
            if (top9Attractions.size() > 1) {
                List<Attraction> rightSrc = top9Attractions.subList(1, Math.min(top9Attractions.size(), 9));
                result.setRightSrc(rightSrc);
            }
        }

        return result;
    }
}